using System;
using System.Drawing;

namespace Geometry
{
	/// <summary>
	/// point, based on doubles
	/// </summary>
	public struct Point2D
	{
		public double x;
		public double y;

		public Point2D(double x, double y)
		{
			this.x = x;
			this.y = y;
		}

		public double Length
		{
			get {return Math.Sqrt(x*x+y*y);}
		}

		public double GetDistance(Point2D p)
		{
			p.x -= x;
			p.y -= y;
			return p.Length;
		}

		public double GetDistance(double x, double y)
		{
			x -= this.x;
			y -= this.y;
			return Math.Sqrt(x*x+y*y);
		}

		#region ToString
		public override string ToString()
		{
			return x.ToString() + " " + y.ToString();
		}

		public string ToString(string format)
		{
			return x.ToString(format) + " " + y.ToString(format);
		}

		public string ToLongString()
		{
			return "x:"+x.ToString() + " y:" + y.ToString();
		}

		public string ToLongString(string format)
		{
			return "x:"+x.ToString(format) + " y:" + y.ToString(format);
		}

		#endregion ToString

		public static implicit operator PointF(Point2D point2D) 
		{
			return new PointF((float)point2D.x, (float)point2D.y);
		}

		public static Point2D operator +(Point2D leftPoint, Point2D rightPoint)
		{
			return new Point2D(leftPoint.x+rightPoint.x, leftPoint.y+rightPoint.y);
		}




	}



	/// <summary>
	/// rectangle, based on doubles
	/// </summary>
	public struct Rectangle2D
	{
		public double x;
		public double y;
		public double width;
		public double height;

		public Rectangle2D(double x, double y, double width, double height)
		{
			this.x = x;
			this.y = y;
			this.width = width;
			this.height = height;
		}

		public Rectangle2D(Point2D topLeftCorner, double width, double height)
		{
			this.x = topLeftCorner.x;
			this.y = topLeftCorner.y;
			this.width = width;
			this.height = height;
		}

		public override string ToString()
		{
			return "x:"+x.ToString() + " y:" + y.ToString()+ " width:" + width.ToString()+ " height:" + height.ToString();
		}



	}


}
